﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using System.Web.UI.HtmlControls;

namespace WebApplication.Admins.Controls
{
    public partial class Search_TinTuc : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
                string searchString = Request.QueryString["Search"] ?? "";
                if (searchString != "")

                    lblDes.Text = "Bạn muốn tìm thông tin của: \"" +"\t"+ searchString+"\t" + "\"";
                Display();
        }

        public void Display()
        {
            int howManyPages = 0;
            string page = Request.QueryString["Page"] ?? "1";
            string searchString = Request.QueryString["Search"] ?? "";
            string firstPageUrl = "";
            string pagerFormat = "";
            if (searchString != null)
            {
                List<Entities.TinTuc> data = TinTuc_BLL.TimKiemNgauNhien(searchString, page, out howManyPages);
                if(data.Count>0)
                {
                repTinTuc.DataSource = data;
                repTinTuc.DataBind();
                firstPageUrl = LinkBLL.ToSearchString(searchString, "1");
                pagerFormat = LinkBLL.ToSearchString(searchString, "{0}");
                }
                else
                {
                    Response.Redirect("~/Admins/TinTuc.aspx");
                }
               
            }
            pagerBottom.Show(int.Parse(page), howManyPages, firstPageUrl, pagerFormat, true);
            
            
        }
    }

}